<!DOCTYPE>
<title>Mouse scrolling by using non-custom scrollbar should scroll its scroller</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../../resources/gesture-util.js"></script>
<script src="../../resources/scrollbar-util.js"></script>
<script src="../../resources/blink-coordinates-util.js"></script>

<style>
html,body {
  margin: 0;
}
.wheelDiv {
  width: 100px;
  height: 100px;
  overflow: auto;
  border: 1px solid black;
  margin: 20px;
  position: absolute;
}
.mainThreadDivPos {
  top: 100px;
}
.compThreadDivPos {
  top: 250px;
}
.slow {
  clip: rect(0px, 1000px, 500px, 0px);
}
.fast {
  will-change: transform;
}
.space {
  height: 1000px;
}
</style>

<!-- Non-composited slow scroller -->
<div class="wheelDiv slow mainThreadDivPos">
  <div class="space">MAIN-THREAD SCROLLING</div>
</div>

<!-- Composited fast scroller -->
<div class="wheelDiv fast compThreadDivPos">
  <div class="space">COMPOSITOR-THREAD SCROLLING</div>
</div>

<script>

window.onload = () => {
  const divSlow = document.querySelector('.slow');
  const divFast = document.querySelector('.fast');
  const rectSlow = divSlow.getBoundingClientRect();
  const rectFast = divFast.getBoundingClientRect();

  promise_test (async () => {
    await waitForCompositorCommit();

    const distance = 10;
    const source_type = GestureSourceType.MOUSE_INPUT;
    const direction = 'down';
    const use_precise_deltas = true;

    let thumb = verticalThumb(divSlow);
    let scrollPromise = waitForScrollEvent(divSlow);
    await smoothScroll(distance,
                       thumb.x, thumb.y,
                       source_type,
                       direction,
                       SPEED_INSTANT,
                       use_precise_deltas);
    await scrollPromise;

    assert_greater_than(divSlow.scrollTop, 0, "Main-thread scrolling div didn't scroll.");

    thumb = verticalThumb(divFast);
    scrollPromise = waitForScrollEvent(divFast);
    await smoothScroll(distance,
                       thumb.x, thumb.y,
                       source_type,
                       direction,
                       SPEED_INSTANT,
                       use_precise_deltas);
    await scrollPromise;
    assert_greater_than(divFast.scrollTop, 0, "Compositor-thread scrolling div didn't scroll.");
  }, "Test mouse scrolling over non-custom scrollbars");
}
</script>
